<?php
/*
 * @Description    : 邮件发送任务
 * @Version        : 1.0.0
 * @Author         : QianLong
 * @Date           : 2020-01-22 15:56:35
 * @LastEditors    : QianLong
 * @LastEditTime   : 2023-01-18 10:58:09
 */

declare(strict_types=1);

namespace App\Job;

use Hyperf\AsyncQueue\Job;
use App\Common\RedisCache;

class SymfonyEmailDataJob extends Job
{
    public $params;

    public function __construct($params)
    {
        $this->params = $params;
    }

    public function handle()
    {
        if (!empty($this->params) && is_array($this->params)) {
            $redisCache = new RedisCache;
            $emailList = array_flip(array_unique(explode(',',$this->params['email'])));
            foreach ($emailList as $email => $in) {
                $emailArray2 = explode('|', $email);
                $this->params['single_email'] = $emailArray2[0];
                $this->params['single_email_user_name'] = isset($emailArray2[1]) ? $emailArray2[1] : '';
                if (!empty($this->params['filter_id']) && $this->params['is_filter'] == 1) {
                    $result = $redisCache->setFilterEmail($this->params['uid'] . ':' . $this->params['filter_id'], $email);
                    if ($result) {
                        queue_push(new SymfonyEmailJob($this->params, $redisCache));
                    }
                } else {
                    queue_push(new SymfonyEmailJob($this->params, $redisCache));
                }
            }
            unset($in, $email, $emailArray2, $result);
        }
    }
}
